package com.sky;

import java.util.concurrent.TimeUnit;

/**
 * @author : wushikai
 * <p>
 * date : 2022-04-08
 */
public class TimeUnitDemo {


    public static void convertTest(String[] args) {


        //convert 1 day to 24 hour
        System.out.println(TimeUnit.DAYS.toHours(1));
        //convert 1 hour to 60*60 second.
        System.out.println(TimeUnit.HOURS.toSeconds(1));
        //convert 3 days to 72 hours.
        System.out.println(TimeUnit.HOURS.convert(3, TimeUnit.DAYS));


    }


    public static void sleepTest() {


        Thread t = new Thread(new Runnable() {
            private int count = 0;

            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        // Thread.sleep(500); //sleep 单位是毫秒
                        TimeUnit.SECONDS.sleep(1); // 单位可以自定义,more convinent
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count++;
                    System.out.println(count);
                }
            }
        });
        t.start();


    }



    public static void main(String[] args){


        sleepTest();


    }

}
